package com.example.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @author mtcarpenter
 * @github https://github.com/mtcarpenter/spring-cloud-learning
 * @desc 微信公众号：山间木匠
 */
@Component
@EnableBinding(StreamBinding.class)
@Slf4j
public class StreamReceiver {

    @StreamListener(StreamBinding.INPUT)
    public void inputMessage(Message message) {
        log.info("StreamReceiver:{}", message);
        log.info("StreamReceiver payload:{}", message.getPayload().toString());
        log.info("msg header class: " + message.getHeaders().getClass().getName());
        log.info("msg header book class: " + message.getHeaders().get("book").getClass().getName());
        log.info("msg header book : " + message.getHeaders().get("book"));
//        log.info("msg header book name: " + ((Book) message.getHeaders().get("book")).getName());
        log.info("msg payload class: " + message.getPayload().getClass().getName());
        log.info("msg payload : " + message.getPayload());
//        log.info("msg payload name: " + ((Book) message.getPayload()).getName());
        log.info("StreamReceiver Headers:{}", message.getHeaders().toString());
//        return 0;
    }


}
